<?php $this->context->layout = 'form';?>

<form class="form-horizontal m" id="form-admin-add">
    <input type="hidden" name='good_id' value="<?=$id?>">
    <table class="table table-bordered">
        <tr>
            <th>规格</th>
            <th>校区名称</th>
            <th>库存（件）</th>
        </tr>
        <?php foreach ($data as $k=>$datum):?>
            <?php foreach ($datum['data'] as $key=>$value):?>
                <tr>
                    <?php if ($key==0):?>
                    <td rowspan="<?=count($datum['data'])?>"><?=$datum['name']?></td>
                    <?php endif;?>
                    <input type="hidden" name="specAll[<?=$k.$key?>][id]" value="<?=$value['id']?>">
                    <input type="hidden" name="specAll[<?=$k.$key?>][good_id]" value="<?=$value['good_id']?>">
                    <input type="hidden" name="specAll[<?=$k.$key?>][spec_id]" value="<?=$value['spec_id']?>">
                    <input type="hidden" name="specAll[<?=$k.$key?>][campus_id]" value="<?=$value['campus_id']?>">
                    <td><?=$value['name']?></td>
                    <td><input type="number" class="form-control" name="specAll[<?=$k.$key?>][stock]" value="<?=$value['stock']?>"></td>
            </tr>
            <?php endforeach;?>
        <?php endforeach;?>
    </table>
</form>

<?php $this->beginBlock('script'); ?>
<script>
    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save("<?=\yii\helpers\Url::to(['spec'])?>", $('#form-admin-add').serialize());
        }
    }
</script>
<?php $this->endBlock(); ?>
